<?php
include 'config/functions.php';

session_start();

if (!empty($_GET['openid_ext1_value_firstname']) && !empty($_GET['openid_ext1_value_lastname']) && !empty($_GET['openid_ext1_value_email'])) {    
    $username = $_GET['openid_ext1_value_firstname'] . $_GET['openid_ext1_value_lastname'];
    $first_name = $_GET['openid_ext1_value_firstname'];
    $last_name =  $_GET['openid_ext1_value_lastname'];
    $email = $_GET['openid_ext1_value_email'];
    //$uid = $_GET['openid_ext1_value_uid'];
    $uid = null;
    $user = new User();
    $userdata = $user->checkUserGoogle('1', 'Google', $username, $email, $first_name, $last_name);
    
    if(!empty($userdata)) {
       // session_start();
        $_SESSION['id'] = $userdata['id'];
        $_SESSION['oauth_id'] = $uid;
        $_SESSION['login'] = "true";
		$_SESSION['logged_in'] = "true";
		$_SESSION['user_role'] = $userdata['user_role'];
        $_SESSION['username'] = $userdata['first_name']." ".$userdata['last_name'];
        $_SESSION['email'] = $userdata['email'];
        $_SESSION['oauth_provider'] = $userdata['oauth_provider'];
        
        header("Location: ../feedback.php");

    } else {
        // Something's missing, go back to square 1
        header('Location: error.php');
    }

}
?>
